package com.ruoyi.project.newhope.device.service.impl;

import java.util.List;
import java.util.Objects;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.newhope.data.mapper.NewHopeCollectDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.newhope.device.mapper.NewHopeInfraredDeviceMapper;
import com.ruoyi.project.newhope.device.domain.NewHopeInfraredDevice;
import com.ruoyi.project.newhope.device.service.INewHopeInfraredDeviceService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 近红外设备Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-02-08
 */
@Service
public class NewHopeInfraredDeviceServiceImpl implements INewHopeInfraredDeviceService 
{
    @Autowired
    private NewHopeInfraredDeviceMapper newHopeInfraredDeviceMapper;
    @Autowired
    private NewHopeCollectDataMapper newHopeCollectDataMapper;

    /**
     * 查询近红外设备
     * 
     * @param id 近红外设备ID
     * @return 近红外设备
     */
    @Override
    public NewHopeInfraredDevice selectNewHopeInfraredDeviceById(Long id)
    {
        return newHopeInfraredDeviceMapper.selectNewHopeInfraredDeviceById(id);
    }

    /**
     * 查询近红外设备列表
     * 
     * @param newHopeInfraredDevice 近红外设备
     * @return 近红外设备
     */
    @Override
    public List<NewHopeInfraredDevice> selectNewHopeInfraredDeviceList(NewHopeInfraredDevice newHopeInfraredDevice)
    {
        return newHopeInfraredDeviceMapper.selectNewHopeInfraredDeviceList(newHopeInfraredDevice);
    }

    /**
     * 新增近红外设备
     * 
     * @param newHopeInfraredDevice 近红外设备
     * @return 结果
     */
    @Override
    public int insertNewHopeInfraredDevice(NewHopeInfraredDevice newHopeInfraredDevice)
    {
        newHopeInfraredDevice.setCreateTime(DateUtils.getNowDate());
        return newHopeInfraredDeviceMapper.insertNewHopeInfraredDevice(newHopeInfraredDevice);
    }

    /**
     * 修改近红外设备
     * 
     * @param newHopeInfraredDevice 近红外设备
     * @return 结果
     */
    @Override
    public int updateNewHopeInfraredDevice(NewHopeInfraredDevice newHopeInfraredDevice)
    {
        // 更新采集数据的对应的字段
        NewHopeInfraredDevice old = newHopeInfraredDeviceMapper.selectNewHopeInfraredDeviceById(newHopeInfraredDevice.getId());
        if (!Objects.equals(old.getLocation(), newHopeInfraredDevice.getLocation())) {
            newHopeCollectDataMapper.updateDeviceLocationByDeviceId(newHopeInfraredDevice.getLocation(), newHopeInfraredDevice.getId());
        }

        newHopeInfraredDevice.setUpdateTime(DateUtils.getNowDate());
        return newHopeInfraredDeviceMapper.updateNewHopeInfraredDevice(newHopeInfraredDevice);
    }

    /**
     * 删除近红外设备对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteNewHopeInfraredDeviceByIds(String ids)
    {
        return newHopeInfraredDeviceMapper.deleteNewHopeInfraredDeviceByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除近红外设备信息
     * 
     * @param id 近红外设备ID
     * @return 结果
     */
    @Override
    public int deleteNewHopeInfraredDeviceById(Long id)
    {
        return newHopeInfraredDeviceMapper.deleteNewHopeInfraredDeviceById(id);
    }
}
